package com.shop2cn.iapi.sqoptrade.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.req.BatchAcceptOrderReq;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.BatchAcceptOrderCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.shenqi.DGSQBuildProxyChainCallService;
import com.ymttest.business.service.shenqi.SqTradingCallService;
import com.ymttest.utils.EnvSetup;

/**
 * 批量接单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SqBatchAcceptOrder {

	private static BatchAcceptOrderReq batchAcceptOrderReq;

	private static BatchAcceptOrderCall batchacceptordercall;
	
	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量接单");
	}

	@Before
	public void caseUp() {

		batchAcceptOrderReq = new BatchAcceptOrderReq();
		batchacceptordercall = new BatchAcceptOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(batchacceptordercall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchAcceptOrder_006() {
		Logger.start(true, "代购神器交易下单支付，非货主手动接单，接单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService.placeOrder(productBean);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			
			// 支付订单
			SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());
			
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			batchAcceptOrderReq.setSellerId(1L);
			batchAcceptOrderReq.setOrderIds(Lists.newArrayList(orderId));
			
			batchacceptordercall.setData(batchAcceptOrderReq);
			batchacceptordercall.callService();
			
			Logger.verifyEquals(String.format("用户1不是订单%s的所有者", orderId),
					batchacceptordercall.getAcceptOrderResultList().get(0)
							.getResultInfo(), "校验resultInforesultInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
